<%@page import="tu.java.movie.MovieImage"%>
<%@page import="java.util.Vector"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page import="tu.java.utils.FileUploadUtil"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%	FileUploadUtil f = new FileUploadUtil();
	List requestInfo = f.uploadFiles(request);
	Map<String, String> formFields = (Map<String, String>) requestInfo.get(0);
	if (formFields == null) {
		formFields = f.mapStringArrToMapString(request.getParameterMap());
	}
	String action = formFields.get("action");
	String movieId = formFields.get("movieId");
	if(action!=null && action.equals("addFiles")){
		Vector<Map> files = (Vector<Map>)requestInfo.get(1);
		if(files!=null && files.size()>0){
			for(int i=0;i<files.size(); i++){
				Map file = (Map)files.get(i);
				MovieImage m = new MovieImage();
				m.setMovieId(Integer.parseInt(movieId));
				m.setMovieImage((byte[])file.get("fileContent"));
				m.addMovieImage();			
			}			
		}
	}
%>
<form name="uploadFile" enctype="multipart/form-data" accept-charset="UTF-8" method="post" action="<%=request.getRequestURI()+"?"+request.getQueryString()%>">
	<input type="hidden" name="action" value="">
	<input type="hidden" name="movieId" value="<%=movieId%>">
	<table class="formtable">
		<tr>
			<td align="right">	
				<input type="file" name="files" accept="image/*" multiple="multiple" onchange="javascript:document.forms.uploadFile.action.value='addFiles'; document.forms.uploadFile.submit();">
			</td>
		</tr>
	</table>
</form>